package com.tml.servlet;

import com.tml.entry.SmbmsUser;
import com.tml.service.IHomeService;
import com.tml.service.impl.HomeService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class HomeServlet   extends HttpServlet {

    //推到推理出
    //写web 项目功能  退出登录，删除用户，修改改用，修改密码
    //1.连接数据库，操作数据，对数据的增删改查    dao层
    //2.对数据返回的数据，进行处理。            service
    //3.跳转页面                             servlet  表现层
    // 数据载体，实体类
    //分层概念
    //web页面===>servlet ===>service ===>dao ===>mysqldb
    //web页面<===servlet <====service<====dao<===


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //组织准备数据的代码写这里
        //第一步，加载驱动
        //HomeService homeService =new HomeService();
        IHomeService homeService = new HomeService();
        List<SmbmsUser> smbmsUserList = homeService.getSmbmsUserAll();
        HttpSession session = req.getSession();
        session.setAttribute("smbmsUserList",smbmsUserList);
        resp.sendRedirect("home.jsp");
        }

    }


